package b3.widget.task
{
	import b3.config.*;
	import b3.model.*;
	import b3.net.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;

	public class TaskIcon extends Sprite
	{
		private var taskId:int;
		
		public function TaskIcon(taskId:int)
		{
			this.taskId = taskId;
			super();
			if (this.numChildren > 0)
			{
				removeChildAt(0);
			}
			var taskConfig:TaskConfig = Config.taskConfigs[taskId];
			//没有任务
			if (taskConfig == null)
				return;
			var IconImage:Class = ResourceHelper.getInstance().getClassByName(taskConfig.iconImage);
			var iconImage:BasicIcon = new BasicIcon(IconImage);
			addChild(iconImage);
			this.addEventListener(MouseEvent.CLICK, onMouseClick);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseClick(event:Event):void
		{
			var taskDialog:TaskDialog = new TaskDialog(taskId);
			taskDialog.x = -taskDialog.width / 2;
			taskDialog.y = -taskDialog.height / 2;
			WidgetManager.getInstance().popOutOneByOne(taskDialog);
		}
		
		private function onMouseOver(event:Event):void
		{
			var globalPoint:Point = this.parent.localToGlobal(new Point(this.x, this.y));
			var taskTip:TaskMessage = new TaskMessage(taskId); 
			taskTip.x = globalPoint.x + 55;
			taskTip.y = globalPoint.y;
			WidgetManager.getInstance().popOutMouseOverMessage(taskTip);
		}

		private function onMouseOut(event:Event):void
		{
			WidgetManager.getInstance().closeMouseOverMessage();
		}
	}
}